// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router';
import _ from 'lodash'

const routes = [
    {
        path: '/',
        name: 'Home',
        component: () => import('../views/hello.vue'), // 懒加载Home组件
    }, 
    {
        path: '/vue/:pathMatch(.*)*',
        name: 'VueApp',
        component: () => import('../views/Home.vue'),
    }
];

const router = createRouter({
    history: createWebHistory('/'),
    routes,
});

// 这个解决了一个异常问题

router.beforeEach((to, from, next) => {
  if (_.isEmpty(history.state.current)) {
    _.assign(history.state, { current: from.fullPath });
  }
  next();
});

export default router;